package cn.iocoder.yudao.module.handguard.service.userbasetable1;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import java.util.*;
import cn.iocoder.yudao.module.handguard.controller.app.userbasetable1.vo.*;
import cn.iocoder.yudao.module.handguard.dal.dataobject.userbasetable1.UserBaseTable1DO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;

import cn.iocoder.yudao.module.handguard.convert.userbasetable1.UserBaseTable1Convert;
import cn.iocoder.yudao.module.handguard.dal.mysql.userbasetable1.UserBaseTable1Mapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.handguard.enums.ErrorCodeConstants.*;

/**
 * 按揭房信贷 Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class UserBaseTable1ServiceImpl implements UserBaseTable1Service {

    @Resource
    private UserBaseTable1Mapper userBaseTable1Mapper;

    @Override
    public Long createUserBaseTable1(UserBaseTable1CreateReqVO createReqVO) {
        // 插入
        UserBaseTable1DO userBaseTable1 = UserBaseTable1Convert.INSTANCE.convert(createReqVO);
        userBaseTable1Mapper.insert(userBaseTable1);
        // 返回
        return userBaseTable1.getId();
    }

    @Override
    public void updateUserBaseTable1(UserBaseTable1UpdateReqVO updateReqVO) {
        // 校验存在
        validateUserBaseTable1Exists(updateReqVO.getId());
        // 更新
        UserBaseTable1DO updateObj = UserBaseTable1Convert.INSTANCE.convert(updateReqVO);
        userBaseTable1Mapper.updateById(updateObj);
    }

    @Override
    public void deleteUserBaseTable1(Long id) {
        // 校验存在
        validateUserBaseTable1Exists(id);
        // 删除
        userBaseTable1Mapper.deleteById(id);
    }

    private void validateUserBaseTable1Exists(Long id) {
        if (userBaseTable1Mapper.selectById(id) == null) {
            throw exception(USER_BASE_TABLE1_NOT_EXISTS);
        }
    }

    @Override
    public UserBaseTable1DO getUserBaseTable1(Long id) {
        return userBaseTable1Mapper.selectById(id);
    }

    @Override
    public List<UserBaseTable1DO> getUserBaseTable1List(Long id) {
        LambdaQueryWrapper<UserBaseTable1DO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(UserBaseTable1DO::getApplicationId,id);
        return userBaseTable1Mapper.selectList(queryWrapper);
    }

    @Override
    public PageResult<UserBaseTable1DO> getUserBaseTable1Page(UserBaseTable1PageReqVO pageReqVO) {
        return userBaseTable1Mapper.selectPage(pageReqVO);
    }

    @Override
    public List<UserBaseTable1DO> getUserBaseTable1List(UserBaseTable1ExportReqVO exportReqVO) {
        return userBaseTable1Mapper.selectList(exportReqVO);
    }

}
